<template>
    <div class="mainDiv">
        <el-row :gutter="20" class="rowHead">
            <el-col :span="10" class="flex_center">
                <el-button type="success" icon="plus" @click="addaccount" v-qx="quanxian.add" style="margin-right: 5px;">收款账户</el-button>
                <el-select v-model="page.zt" @change="getList" class="ml w200" v-qx="quanxian.status">
                    <el-option v-for="(o, key) in leaves" :label="o.
                    txt" :value="o.val" :key="key"></el-option>
                </el-select>
            </el-col>                
            <el-col :span="14" class="flex_end_center">
                <el-input style="width: 50%;" placeholder="搜索账户名称、账号" @keyup.enter.native="getList" v-model="page.search">
                    <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
                </el-input>
                <el-button type="primary" icon="h-shuaxin1" style="margin-left:5px" @click="getList">刷新列表</el-button>
            </el-col>           
        </el-row>
        <el-table :data="list" :stripe="true" height="100%">
            <!-- <el-table-column prop="id" label="ID" width="80"></el-table-column> -->
            <el-table-column prop="number" label="账户编号"></el-table-column>
            <el-table-column prop="name" label="账户名称"></el-table-column>
            <el-table-column prop="accounttype" label="账户类型">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.accounttype" typeName="accountType"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="accountsn" label="帐号" show-overflow-tooltip></el-table-column>
            <el-table-column prop="remarks" label="账户描述" show-overflow-tooltip></el-table-column>
            <el-table-column prop="addtime" label="添加日期" show-overflow-tooltip>
                <template slot-scope="scope">
                    {{scope.row.addtime|hourTime}}
                </template>
            </el-table-column>
            <el-table-column label="产品操作" width="160">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisable">
                        <el-button icon="el-icon-h-chakan" type="info" size="mini" @click="look(scope.row.id)" v-qx="quanxian.look"></el-button>
                        <el-button icon="el-icon-edit" type="warning" size="mini" @click="edit(scope.row)" v-qx="quanxian.edit"></el-button>
                        <el-tooltip content="停用账户" placement="top" :open-delay="800" v-qx="quanxian.unstop">
                            <el-button icon="el-icon-h-jinyong" type="danger" size="mini" @click="unstop(scope.row.id,1)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-button-group v-else>
                        <el-button type="info" icon="el-icon-h-chakan" size="mini" @click="look(scope.row.id)" v-qx="quanxian.look"></el-button>
                        <el-button type="success" icon="el-icon-h-qiyong2" size="mini" @click="unstop(scope.row.id,0)" v-qx="quanxian.unstop"></el-button>
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
        <div class="block bg-light center">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
import Tags from '@/components/orderTags.vue'
import Account from '@/service/shop/account.js'

export default {
  name: 'accountList',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: '',
        zt: 0,
        times: ''
      },
      leaves: [{
        txt: '正常使用',
        val: 0
      }, {
        txt: '停止使用',
        val: 1
      }],
      quanxian: {
        add: 'pay_add',
        status: 'pay_status',
        look: 'pay_look',
        edit: 'pay_edit',
        unstop: 'pay_unstop'
      },
      pickerOptions2: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  methods: {
    addaccount: async function () {
      let res = await Account.openAddAccount()
      if (res && res.data) {
        C.success(res.data)
        this.getList()
      }
    },
    unstop: async function (id, tp) {
      if (tp) {
        C.confirm('停用当前账户, 是否继续?', async () => {
          let res = await C.ajax('/shop/account/unstop', { id: id, status: tp }, 'post')
          if (res) {
            C.success(res.data)
            this.getList()
          }
        })
      } else {
        let res = await C.ajax('/shop/account/unstop', { id: id, status: tp }, 'post')
        if (res) {
          C.success(res.data)
          this.getList()
        }
      }
    },
    // 查看当前订单
    look: function (id) {
      C.openBrowserWindow('/accountInfo', { id: id }, { width: 1000, height: 800, useSpa: false, spaModel: 'shop', transparent: true, frame: false })
    },
    edit: async function (row) {
      let res = await Account.openAddAccount(row)
      if (res && res.data) {
        C.success(res.data)
        this.getList()
      }
    },

    sizeChange: function (val) {
      this.page.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.getList()
    },

    getList: async function () {
      let data = await C.ajax('/shop/account/accountlist', { page: JSON.stringify(this.page) }, 'post')
      if (data) {
        this.list = data.data
        this.total = data.count
      }
    }
  },
  mounted: function () {
    this.getList()
  },
  components: { Tags }
}
</script>